//
//  JXPagingSegment_Guide.swift
//  PPKit
//
//  Created by xiaopin on 2022/4/18.
//  Copyright © 2022 sowell.com. All rights reserved.
//

/*
 JXPagingView和JXSegmentView编写规范标准统一模式：
 
 一、没有继承基类的写法：参考MTMatchHomeViewController
 1.导入import JXSegmentedView
 2.声明数据源和内容容器
 let segmentedDataSource = JXSegmentedTitleImageDataSource()
 let segmentedView = JXSegmentedView()
 lazy var listContainerView: JXSegmentedListContainerView! = {
     return JXSegmentedListContainerView(dataSource: self)
 }()
 
 3.构造数据源和sgementedView
 let titles = ["MT_Football".localized, "MT_Basketball".localized]
 segmentedDataSource.titles = titles
 segmentedDataSource.titleImageType = .onlyImage
 segmentedDataSource.imageSize = CGSize(width: 70.scale, height: 35.scale)
 segmentedDataSource.itemSpacing = 10.scale
 segmentedDataSource.normalImageInfos = ["tab_football", "tab_basketball"]
 segmentedDataSource.selectedImageInfos = ["tab_football_selected", "tab_basketball_selected"]
 segmentedDataSource.loadImageClosure = {(imageView, normalImageInfo) in
     //如果normalImageInfo传递的是图片的地址，你需要借助SDWebImage等第三方库进行图片加载。
     //加载bundle内的图片，就用下面的方式，内部默认也采用该方法。
     imageView.image = UIImage(named: normalImageInfo)
 }
 segmentedView.defaultSelectedIndex = 0
 segmentedView.frame = CGRect(x: 0, y: 0, width: 170.scale, height: 41.scale)
 segmentedView.dataSource = segmentedDataSource
 segmentedView.delegate = self
 segmentedView.listContainer = listContainerView
 
 //普通底部背景的指示器
 let indicatorView = JXSegmentedIndicatorLineView()
 indicatorView.indicatorColor = pp_color(.C159F48)
 indicatorView.indicatorWidth = 54.scale
 indicatorView.indicatorHeight = 2
 segmentedView.indicators = [indicatorView]

 navigationItem.titleView = segmentedView
 view.addSubview(listContainerView)
 
 4.编写代理方法
 extension MTMatchHomeViewController: JXSegmentedListContainerViewDataSource,JXSegmentedViewDelegate {
     func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
         if let titleDataSource = segmentedView.dataSource as? JXSegmentedBaseDataSource {
             return titleDataSource.dataSource.count
         }
         return 0
     }

     func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
         if index == 0 {
             let vc = MTMatchMainController_Football()
             return vc
         }else{
             let vc = MTMatchMainController_Basketball()
             return vc
         }
     }
     
     func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
         
     }
 }
 
 5.编写listContainerView的子页面，实现代理
 
 extension MTMatchMainController_Basketball: JXSegmentedListContainerViewListDelegate {
     func listView() -> UIView {
         return view
     }
 }
 
 二、继承基类的写法：
 */
